$(document).ready(function(){
	
	var isHaveFJ = $("#FJID").text();
	if(isHaveFJ!==null){
		$("#paListDIV").show();
	}else{
		$("#b_bialog").show();
	}
	
	$.ajax({
  		type: "post",
 		url: "hmk/getWukuType_getWukuType.action",
  		success:function(data){
  			$.each(data.typeList,function(i,n){
  				$("<option value="+n.tpyeId+">"+n.tpyeName+"</option>").appendTo('#caseTypeID');
			});
			//设置选中的select 			
			var type = $("#DIS_ctID").text();
			//alert(type);
			$("#caseTypeID option").each(function(){
				var v = $(this).attr("value");
				if(v==type){
					$(this).attr("selected","selected");
				}
			});
  		}
	});
	
	$.ajax({
  		type: "post",
 		url: "hmk/getLevel_findAll.action",
  		success:function(data){
  			$.each(data.caseLevelList,function(i,n){
  				$("<option value="+n.levelId+">"+n.levelName+"</option>").appendTo('#caseLevelID');
			});
			//设置选中的select 			
			var type = $("#DIS_clID").text();
			//alert(type);
			$("#caseLevelID option").each(function(){
				var v = $(this).attr("value");
				if(v==type){
					$(this).attr("selected","selected");
				}
			});
  		}
	});
	
	$("#dialog-form").dialog({
		autoOpen: false,
		width: 460,
		modal: true,
		resizable: false,
	    close: function() {
			$("#FJID").text("");
			$("#FJNameID").text("");
			var realName=$(window.frames["uploadFrame"].document).find("#RealNameID").text();
			var objectName=$(window.frames["uploadFrame"].document).find("#ObjectNameID").text();
			$("#FJID").text(objectName);
			$("#FJNameID").text(realName);
			$("#b_bialog").hide();
			$("#paListDIV").show();
	 	}
	});
	
	$("#b_bialog").click(function(){
		$("#uploadFrame").attr("src","/ag/hmk/uploadCase.jsp");
		$('#dialog-form').dialog('open'); //open dialog
	});
	
	/////////////////////
	$("#acceptForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
            //form.submit();   //提交表单
       var caseID = $("#caseID").text();
		var typeID=$('#caseTypeID option:selected').val();
		var caseLevelID=$('#caseLevelID option:selected').val();
		var caseName=$('#caseNameID').val();
		var caseDetail=$('#caseDetailID').val();
		var caseKeyword = $('#caseKeyID').val();
		
		var FJID =$("#FJID").text();
		var FJNameID =$("#FJNameID").text();
		if(FJID!=null && FJID.length!==0 && FJNameID!=null && FJNameID.length!==0  ){
			 $.ajax({
  			type: "post",
 			url: "hmk/saveCase_updateCase.action",
 			data:{
 				  caseID1:caseID,typeID1:typeID,caseLevel1:caseLevelID,caseName1:caseName,caseDetail1:caseDetail,
 				  caseKwstr1:caseKeyword,fileID1:FJID,fileNameID1:FJNameID
 				 },
  			success:showData
		 });
		  }else{
		  	alert("请先添加附件");
		  }
		  
        },
		rules: {
			'caseTypeID':'required',
			'caseLevelID':'required',
			'caseNameID':'required'
			
		} ,
		messages: {
			'caseTypeID':"*必须选",
			'caseLevelID':"*必须选",
			'caseNameID':"*必须选"
			
		}
	});
	//////////////////////
	
	
	/*
	//更新案例
	$('#UPDATEcaseID').click(function(){
		var caseID = $("#caseID").text();
		var typeID=$('#caseTypeID option:selected').val();
		var caseLevelID=$('#caseLevelID option:selected').val();
		var caseName=$('#caseNameID').val();
		var caseDetail=$('#caseDetailID').val();
		var caseKeyword = $('#caseKeyID').val();
		
		var FJID =$("#FJID").text();
		var FJNameID =$("#FJNameID").text();
		
		if(typeID!==null && typeID.length!==0 && caseLevelID!==null &&  caseLevelID.length!==0 && 
		   caseName!==null && caseName.length!==0 ){
			
		 $.ajax({
  			type: "post",
 			url: "hmk/saveCase_updateCase.action",
 			data:{
 				  caseID1:caseID,typeID1:typeID,caseLevel1:caseLevelID,caseName1:caseName,caseDetail1:caseDetail,
 				  caseKwstr1:caseKeyword,fileID1:FJID,fileNameID1:FJNameID
 				 },
  			success:showData
		 });
		}else{
			alert("带*号的必填！");
		}
		
	});
	
	*/
	function showData(data){
		if(data.ajaxRST=='1'){
			alert("保存成功！");
			var caseID = $("#caseID").text();
			window.location.href="/ag/hmk/findOneCase_findOneCase.action?caseID1="+caseID;
		}else{
			alert("保存失败！");
		}
	}
	
	//返回案例详情
	$('#BACK_casedetail').click(function(){
		var caseID = $("#caseID").text();
		window.location.href="/ag/hmk/findOneCase_findOneCase.action?caseID1="+caseID;
	});
	
	
});


	function getPaList(){	
		var timestamp = Date.parse(new Date());
		$.get("hmk/session_findPaList.action?ts="+timestamp,null,getPaListRst);
	}

	function getPaListRst(data){
		if(data.paList!==null){
			$.each(data.paList,function(i,n){
				$("#FJID").text(n.paId);
				$("#FJNameID").text(n.paName);
			});
			$("#b_bialog").hide();
			$("#paListDIV").show();		
		}
	}


	function delFJ(v){
		alert("删除成功");
		$("#FJID").text("");
		$("#FJNameID").text("");
		$("#b_bialog").show();
		$("#paListDIV").hide();
		//var timestamp = Date.parse(new Date());
		//$.get("hmk/session_DeleteSession.action?ts="+timestamp,null,delSessionOK);
	}
	
	function delSessionOK(data){
		alert("删除成功");
		$("#FJID").text("");
		$("#FJNameID").text("");
		$("#b_bialog").show();
		$("#paListDIV").hide();
	}
	